﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Windows;

namespace eWallet
{
	internal static class ExceptionHandling
	{

		public static void DisplayException(Exception ex)
		{
			DisplayException(null, true, ex);
		}

		public static void DisplayException(string message, Exception ex)
		{
			DisplayException(message, true, ex);
		}

		public static void DisplayException(string message, bool traceException, Exception ex)
		{
			if (traceException)
			{
				TraceSource source = new TraceSource("eWallet");
				if (!string.IsNullOrEmpty(message))
				{
					source.TraceData(TraceEventType.Error, 0, message, ex);
				}
				else
				{
					source.TraceData(TraceEventType.Error, 0, ex);
				}
			}

			StringBuilder builder = new StringBuilder();
			if (!string.IsNullOrEmpty(message))
			{
				builder.AppendLine(message);
			}
			builder.AppendLine(ex.ToString());
			MessageBox.Show(builder.ToString(), "Exception", MessageBoxButton.OK, MessageBoxImage.Error);
		}

	}
}
